﻿using System;
using System.Security.Cryptography;
using System.Text;

namespace EasyCommonCore.Common
{
    /// <summary>
    /// 密码
    /// </summary>
    public static class CryptogramCommon
    {
        #region Md5加密
        /// <summary>
        /// Md5加密
        /// </summary>
        /// <param name="parameter">待加密字符串</param>
        /// <returns></returns>
        public static string ToMd5(this string parameter)
        {
            using (var md5 = MD5.Create())
            {
                var result = md5.ComputeHash(Encoding.UTF8.GetBytes(parameter));
                var strResult = BitConverter.ToString(result);
                return strResult.Replace("-", "");
            }
        }

        #endregion

        #region SHA1加密
        /// <summary>
        /// SHA1加密
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        public static string ToSha1(this string parameter)
        {
            var sha1 = SHA1.Create();
            return Encoding.ASCII.GetString(sha1.ComputeHash(Encoding.ASCII.GetBytes(parameter)));
        }

        #endregion
    }
}
